import QtQuick 1.1
import com.nokia.meego 1.0


PageStackWindow {
    id: appWindow

    initialPage: mainPage

    MainPage {
        id: mainPage
    }

    TimeDiffPage {
        id: timeDiffPage
    }

    ToolBarLayout {
        id: commonTools
        visible: true
        ToolIcon {
            platformIconId: "toolbar-view-menu"
            anchors.right: (parent === undefined) ? undefined : parent.right
            onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
        }
    }

    Page{
        id: aboutPage

        Rectangle {
            id: aboutWindow

            color: "#4c0094"
            gradient: Gradient {
                GradientStop {
                    position: 0.00;
                    color: "#c7b8fa";
                }
                GradientStop {
                    position: 0.60;
                    color: "#ffffff";
                }
            }

            anchors.left: parent.left
            anchors.leftMargin: 0
            anchors.top: parent.top
            width: aboutPage.width
            height: aboutPage.height


            Row {
                id: aboutMainRow
                height: 70

                Image {
                    id: appLogo
                    x: 0; y: 0
                    width: 64; height: 64
                    source: "qrc:/icon_withoutBG"
                    MouseArea {
                        anchors.fill: parent
                        onClicked: Qt.openUrlExternally("http://dadablog.net/HarmattanApps")
                    }
                }


                Rectangle {
                    Text {
                        id: txtAppName
                        x: 80; y: 10
                        text: qsTr("Time Calculator v1.0")
                        color: "#3f0064"
                        font { family: "Helvetica"; pixelSize: 24; bold: true; }
                        MouseArea {
                            anchors.fill: parent
                            onClicked: Qt.openUrlExternally("http://dadablog.net/HarmattanApps")
                        }
                    }

                    Text {
                        id: txtAppURL
                        x: 80; y: 40
                        text: "DaDaBlog.net/HarmattanApps"
                        color: "#3f0064"
                        font { family: "Helvetica"; pixelSize: 24; bold: true; }
                        MouseArea {
                            anchors.fill: parent
                            onClicked: Qt.openUrlExternally("http://dadablog.net/HarmattanApps")
                        }
                    }
                }
            }

            Flickable {
                id: flickAbout
                anchors.left: parent.left
                anchors.leftMargin: 0
                anchors.top: aboutMainRow.bottom; anchors.topMargin: 40
                contentHeight: aboutPage.width>=800 ? aboutPage.height * 2.35 : aboutPage.height * 1.5

                width: aboutPage.width
                height: aboutPage.height
                clip: true

                flickableDirection: Flickable.VerticalFlick
                boundsBehavior: Flickable.DragOverBounds

                Column {
                    Text {
                        id: txtAppDesc1
                        x: 10
                        width: aboutPage.width - 20
                        text: qsTr("With Time Calculator, you can add or subtract a number of years, months, days, hours, minutes, or seconds (decimal supported) to or from a date / time value:\n")

                        font { family: "Helvetica"; pixelSize: 22}
                        wrapMode: Text.WordWrap;
                    }


                    Image {
                        id: imgCalcPlusMinus
                        x: (aboutPage.width / 2) - 160
                        width: 320;
                        source: qsTr("qrc:/icon_plusminus")
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                appWindow.pageStack.clear()
                                appWindow.pageStack.push(mainPage)
                            }
                        }
                    }

                    Text {
                        id: txtAppDesc2
                        x: 10
                        width: aboutPage.width - 20
                        text: qsTr("\nYou can also find out the difference between two date/time:\n")

                        font { family: "Helvetica"; pixelSize: 22}
                        wrapMode: Text.WordWrap;
                    }


                    Image {
                        id: imgCalcTimeDiff
                        x: (aboutPage.width / 2) - 160
                        width: 320;
                        source: qsTr("qrc:/icon_timediff")
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                appWindow.pageStack.clear()
                                appWindow.pageStack.push(timeDiffPage)
                            }
                        }
                    }

                    Text {
                        id: txtAppDesc3
                        x: 10
                        width: aboutPage.width - 20
                        text: qsTr("According to the definition of the Gregorian calendar, the following assumptions are made in this application:\n\n" +
                                   " 1 Year = 365.25 days\n" +								   
                                   " 1 Month = 30.436875 days\n" +
                                   " 1 Week = 7 days\n" +
                                   " 1 Day = 24 hours\n" +
                                   " 1 Business Day = A day in between Monday and Friday inclusive, except local public holidays.\n" +
                                   " 1 Hour = 60 Minutes\n" +
                                   " 1 Minute = 60 Seconds\n" +
                                   " Earliest date supported: 4713/01/02 B.C.\n" +
                                   " Earliest Selectable Date: 1900/01/01 00:00:00\n" +
                                   " Latest Selectable Date: 2099/12/31 23:59:59\n" +
								   " Largest Plus/Minus Value: 99999\n" +
								   " A.D. 2012 - 2012 years = 1 B.C., as there is no Year 0 by definition\n\n" + 
                                   "Notice: Calculation results of this application are for reference purpose only; their accuracy is not guaranteed.\n")

                        font { family: "Helvetica"; pixelSize: 22}
                        wrapMode: Text.WordWrap;
                    }

                }

            }
            Rectangle {
                id: aboutProduct
                x: 0; y: aboutPage.height - 50
                width: aboutPage.width /2
                height:  50
                color: "#d9d9d9"

                Text {
                    text: qsTr("Copyright Information")
                    font { family: "Helvetica"; pixelSize: 20; bold: true }
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: aboutProductDialog.open()
                }

                QueryDialog {
                    id: aboutProductDialog
                    titleText: qsTr("TimeCalc v1.0")
                    acceptButtonText: qsTr("OK")
                    message: qsTr("for MeeGo 1.2 Harmattan\n(C)Amanda Lam, 2012 All rights reserved.")
                }
            }

            Rectangle {
                id: btnBack
                width: aboutPage.width / 2
                height:  50
                color: "#e6ccff"

                x: aboutPage.width / 2; y: aboutPage.height - 50
                Text {
                    text: qsTr("< Back")
                    anchors.fill: parent
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font { family: "Helvetica"; pixelSize: 20; bold: true; }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: appWindow.pageStack.pop()
                }
            }
        }
    }
    Menu {
        id: myMenu
        visualParent: pageStack
        MenuLayout {
            MenuItem {
                text: qsTr("Sponsor")
                onClicked: Qt.openUrlExternally(qsTr("http://dadablog.net/maemo/donation.html"))
            }
            MenuItem {
                text: qsTr("Plus/Minus Time")
                onClicked: {
                    appWindow.pageStack.clear()
                    appWindow.pageStack.push(mainPage)
                }
            }
            MenuItem {
                text: qsTr("Get Time Difference")
                onClicked: {
                    appWindow.pageStack.clear()
                    appWindow.pageStack.push(timeDiffPage)
                }
            }
            MenuItem {
                text: qsTr("About this app")
                onClicked: appWindow.pageStack.push(aboutPage)
            }
            MenuItem {
                text: qsTr("Exit")
                onClicked: Qt.quit()
            }
        }
    }
}
